<?php

defined('MYLITS') ? '' : exit('No direct script access allowed');

/**
 * @version     1.0.0
 * @package     mylits engine
 * @license     GNU General Public License version 3
 * @author      Arfan Fudyartanto D N <arfan@mylits.com> - http://engine.mylits.com
 */
class menuHelper {

    public static function arrangeMenus($data) {
        $result = array();
        foreach ($data as $menuItem) {
            $id = $menuItem['id'];
            unset($menuItem['id']);
            $result[$id] = $menuItem;
        }
        return $result;
    }

    public static function menusToHtml($menus) {
        $str = '<ul>';
        foreach ($menus as $menuItem) {
            $child = '';
            $liclass = array($menuItem['class']);
            if (isset($menuItem['child'])) {
                $liclass[] = 'parent';
                $child = self::menusToHtml($menuItem['child']);
            }
            $link = BASE_URL . $menuItem['path'];
            $aclass = array($menuItem['class']);
            if ($menuItem['path'] == '#') {
                $link = 'javascript:void(0)';
                $aclass[] = 'separator';
            }
            $sliclass = '';
            if (!empty($liclass)) {
                $sliclass = ' class="' . implode(' ', $liclass) . '"';
            }
            $saclass = '';
            if (!empty($aclass)) {
                $saclass = ' class="' . implode(' ', $aclass) . '"';
            }
            $str .= '<li'.$sliclass.'><a ' . $saclass . ' href="' . $link . '"><label>' . $menuItem['name'] . '</label></a>'
                    . $child . '</li>';
        }
        $str .= '</ul>';
        return $str;
    }

}

?>
